package com.jy.modules.cims.component.common.service;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.data.common.dao.TCMmRaisePlanDao;
import com.jy.modules.cims.data.common.dto.TCMmRaisePlanDTO;
import com.jy.platform.api.org.SessionAPI;
import com.jy.platform.api.org.UserInfo;
import com.jy.platform.core.common.BaseDTO;


/**
 * @classname: TCMmRaisePlanService
 * @description: 定义  T_C_MM_RAISE_PLAN 实现类
 * @author:  dell
 */
@Service("com.jy.modules.cims.component.common.service.TCMmRaisePlanService")
public class TCMmRaisePlanService implements Serializable {

    private static final long serialVersionUID = 1L;
    
	@Autowired
	private TCMmRaisePlanDao dao;
	
	@Autowired
	private SessionAPI sessionAPI;

	/**
     * @author dell
     * @description: 分页查询 T_C_MM_RAISE_PLAN列表
     * @date 2015-09-06 15:04:04
     * @param searchParams 条件
     * @return
     * @throws
     */ 
	public List<TCMmRaisePlanDTO> searchTCMmRaisePlanByPaging(Map<String,Object> searchParams) throws Exception {
		List<TCMmRaisePlanDTO> dataList =  dao.searchTCMmRaisePlanByPaging(searchParams);
		return dataList;
	}
	/**
     * @author dell
     * @description: 按条件查询T_C_MM_RAISE_PLAN列表
     * @date 2015-09-06 15:04:04
     * @param searchParams 条件
     * @return
     * @throws
     */
	public List<TCMmRaisePlanDTO> searchTCMmRaisePlan(Map<String,Object> searchParams) throws Exception {
	    List<TCMmRaisePlanDTO> dataList = dao.searchTCMmRaisePlan(searchParams);
        return dataList;
    }
	/**
     * @author dell
     * @description: 查询T_C_MM_RAISE_PLAN对象
     * @date 2015-09-06 15:04:04
     * @param id
     * @return
     * @throws
     */ 
	public TCMmRaisePlanDTO queryTCMmRaisePlanByPrimaryKey(String id) throws Exception {
		
		TCMmRaisePlanDTO dto = dao.findTCMmRaisePlanByPrimaryKey(id);
		
		if(dto == null) dto = new TCMmRaisePlanDTO();
		
		return dto;
		
	}
	
	/**
	 * 
	 * @Description 
	 * @param id
	 * @return
	 * @throws Exception   
	 * TCMmRaisePlanDTO  
	 * @throws
	 * @author zhangmi
	 * @date 2016-7-5
	 */
	public TCMmRaisePlanDTO queryTCMmRaisePlanByIsUpdate(String id) throws Exception {
		
		TCMmRaisePlanDTO dto = dao.findTCMmRaisePlanByIsUpdate(id);
		
		if(dto == null) return null;
		
		return dto;
		
	}

	/**
     * @title: insertTCMmRaisePlan
     * @author dell
     * @description: 新增 T_C_MM_RAISE_PLAN对象
     * @date 2015-09-06 15:04:04
     * @param dto
     * @return
     * @throws
     */
	@SuppressWarnings("all")
	public Long insertTCMmRaisePlan(TCMmRaisePlanDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		int count = dao.insertTCMmRaisePlan(paramMap);
		
		TCMmRaisePlanDTO resultDto = (TCMmRaisePlanDTO) paramMap.get("dto");
		Long keyId = resultDto.getId();
		return keyId;
	}
	/**
     * @title: updateTCMmRaisePlan
     * @author dell
     * @description: 修改 T_C_MM_RAISE_PLAN对象
     * @date 2015-09-06 15:04:04
     * @param paramMap
     * @return
     * @throws
     */
	public void updateTCMmRaisePlan(TCMmRaisePlanDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		dao.updateTCMmRaisePlan(paramMap);
	}
	/**
	 * 
	 * @Description 募集计划修改功能
	 * @param dto
	 * @throws Exception   
	 * void  
	 * @throws
	 * @author zhangmi
	 * @date 2016-7-5
	 */
	public void updateTCMmRaisePlanStatus(TCMmRaisePlanDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		UserInfo userInfo = sessionAPI.getCurrentUserInfo();
		if (userInfo != null) {
			dto.setModifyTime(new Timestamp(System.currentTimeMillis()));
			dto.setModifyBy(userInfo.getUserId().toString());
		}
		paramMap.put("dto", dto);
		dao.updateTCMmRaisePlanStatus(paramMap);
	}
	
	/**
	 * 
	 * @Description 募集计划更新项目总额
	 * @throws Exception   
	 * void  
	 * @throws
	 */
	public void updateTCMmRaisePlanItemSum() throws Exception {
		
		dao.updateTCMmRaisePlanItemSum();
	}
	
	/**
     * @title: deleteTCMmRaisePlanByPrimaryKey
     * @author dell
     * @description: 删除 T_C_MM_RAISE_PLAN,按主键
     * @date 2015-09-06 15:04:04
     * @param paramMap
     * @throws
     */ 
	public void deleteTCMmRaisePlanByPrimaryKey(BaseDTO baseDto,String ids) throws Exception {
		if(StringUtils.isEmpty(ids)) throw new Exception("删除失败！传入的参数主键为null");
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", baseDto);
		paramMap.put("ids", ids);
		dao.deleteTCMmRaisePlanByPrimaryKey(paramMap);
	}

}

